﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Controls="clr-namespace:MahApps.Metro.Controls"
                    xmlns:Converters="clr-namespace:MahApps.Metro.Converters"
                    xmlns:options="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options"
                    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                    mc:Ignorable="options">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.Buttons.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <SolidColorBrush x:Key="IdealForegroundDisabledBrush" Color="#ADADAD" options:Freeze="True" />

    <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
    <Converters:ToUpperConverter x:Key="ToUpperConverter" />

    <ControlTemplate x:Key="CleanWindowTemplate"
                     TargetType="{x:Type Controls:MetroWindow}">
        <Grid>
            <AdornerDecorator>
                <Grid Background="{TemplateBinding Background}">
                    <Grid.ColumnDefinitions>
                        <!-- icon -->
                        <ColumnDefinition Width="Auto" />
                        <!-- left window commands -->
                        <ColumnDefinition Width="Auto" />
                        <!-- title -->
                        <ColumnDefinition Width="*" />
                        <!-- right window commands -->
                        <ColumnDefinition Width="Auto" />
                        <!-- min,max,close buttons -->
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>

                    <!-- icon -->
                    <ContentControl x:Name="PART_Icon"
                                    Focusable="False"
                                    Grid.Row="0"
                                    Grid.Column="0"
                                    Panel.ZIndex="1"
                                    Content="{TemplateBinding Icon}"
                                    ContentTemplate="{TemplateBinding IconTemplate}"
                                    HorizontalContentAlignment="Stretch"
                                    VerticalContentAlignment="Stretch"
                                    MinWidth="{Binding TitlebarHeight, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
                                    Height="{Binding TitlebarHeight, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
                                    Visibility="{TemplateBinding ShowIconOnTitleBar, Converter={StaticResource BooleanToVisibilityConverter}}" />

                    <!-- the left window commands -->
                    <ContentPresenter x:Name="PART_LeftWindowCommands"
                                      Focusable="False"
                                      Content="{Binding LeftWindowCommands, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
                                      Panel.ZIndex="1"
                                      Grid.Row="0"
                                      Grid.Column="1"
                                      Grid.RowSpan="2"
                                      VerticalAlignment="Top"
                                      TextElement.Foreground="{DynamicResource BlackColorBrush}"
                                      Height="{Binding TitlebarHeight, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
                                      Visibility="{TemplateBinding ShowTitleBar, Converter={StaticResource BooleanToVisibilityConverter}}" />

                    <!-- the title bar -->
                    <Grid x:Name="PART_TitleBar"
                          Focusable="False"
                          Grid.Row="0"
                          Grid.Column="0"
                          Grid.ColumnSpan="5"
                          Height="{Binding TitlebarHeight, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
                          Visibility="{TemplateBinding ShowTitleBar, Converter={StaticResource BooleanToVisibilityConverter}}">

                        <!--This (empty) element is used so everything still responds to drag-->
                        <Label VerticalContentAlignment="Center"
                               HorizontalContentAlignment="Center">
                            <ContentControl x:Name="TitleControl"
                                            Focusable="False"
                                            Content="{TemplateBinding Title}"
                                            ContentTemplate="{TemplateBinding TitleTemplate}"
                                            HorizontalAlignment="Center">
                                <ContentControl.Foreground>
                                    <MultiBinding Converter="{x:Static Converters:BackgroundToForegroundConverter.Instance}">
                                        <Binding RelativeSource="{RelativeSource TemplatedParent}"
                                                 Path="Background"
                                                 Mode="OneWay" />
                                        <Binding RelativeSource="{RelativeSource TemplatedParent}"
                                                 Path="TitleForeground"
                                                 Mode="OneWay" />
                                    </MultiBinding>
                                </ContentControl.Foreground>
                            </ContentControl>
                        </Label>

                    </Grid>

                    <!-- the right window commands -->
                    <ContentPresenter x:Name="PART_RightWindowCommands"
                                      Focusable="False"
                                      Content="{Binding RightWindowCommands, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
                                      Panel.ZIndex="1"
                                      Grid.Row="0"
                                      Grid.Column="3"
                                      Grid.RowSpan="2"
                                      VerticalAlignment="Top"
                                      TextElement.Foreground="{DynamicResource BlackColorBrush}"
                                      Height="{Binding TitlebarHeight, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
                                      Visibility="{TemplateBinding ShowTitleBar, Converter={StaticResource BooleanToVisibilityConverter}}" />

                    <!-- the window button commands -->
                    <Controls:WindowButtonCommands x:Name="PART_WindowButtonCommands"
                                                   Focusable="False"
                                                   Panel.ZIndex="1"
                                                   Grid.Row="0"
                                                   Grid.Column="4"
                                                   Grid.RowSpan="2"
                                                   VerticalAlignment="Top"
                                                   UseLayoutRounding="True"
                                                   Height="{Binding TitlebarHeight, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}" />

                    <!-- the main window content -->
                    <Controls:MetroContentControl Grid.Row="1"
                                                  Grid.Column="0"
                                                  Grid.ColumnSpan="5"
                                                  IsTabStop="False"
                                                  UseLayoutRounding="True"
                                                  FocusVisualStyle="{x:Null}"
                                                  OnlyLoadTransition="True"
                                                  TransitionsEnabled="{TemplateBinding WindowTransitionsEnabled}">
                        <ContentPresenter />
                    </Controls:MetroContentControl>

                    <!-- disables the main content when a modal flyout is shown -->
                    <Rectangle Grid.Row="0"
                               Grid.RowSpan="2"
                               Grid.ColumnSpan="5"
                               Grid.Column="0"
                               Name="PART_FlyoutModal"
                               Fill="{DynamicResource BlackColorBrush}"
                               Opacity="0.5"
                               Visibility="Hidden" />

                    <!-- flyouts -->
                    <ContentControl Grid.Row="0"
                                    Grid.Column="0"
                                    Grid.ColumnSpan="5"
                                    Grid.RowSpan="2"
                                    Panel.ZIndex="2"
                                    Focusable="False"
                                    KeyboardNavigation.TabNavigation="None"
                                    Content="{Binding Flyouts, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
                                    VerticalAlignment="Stretch" />

                    <!-- Container for inactive dialogs. -->
                    <Grid Grid.Row="0"
                          Grid.Column="0"
                          Grid.ColumnSpan="5"
                          Grid.RowSpan="2"
                          Panel.ZIndex="3"
                          FocusVisualStyle="{x:Null}"
                          x:Name="PART_MetroInactiveDialogsContainer" />

                    <!-- Used to create that overlay effect. Can be used for anything. -->
                    <Grid Grid.Row="0"
                          Grid.Column="0"
                          Grid.ColumnSpan="5"
                          Grid.RowSpan="2"
                          Panel.ZIndex="4"
                          Focusable="False"
                          FocusVisualStyle="{x:Null}"
                          x:Name="PART_OverlayBox"
                          Background="{DynamicResource BlackColorBrush}"
                          Opacity="0"
                          Visibility="Hidden" />

                    <!-- Container for the active dialog. -->
                    <Grid Grid.Row="0"
                          Grid.Column="0"
                          Grid.ColumnSpan="5"
                          Grid.RowSpan="2"
                          Panel.ZIndex="5"
                          FocusVisualStyle="{x:Null}"
                          x:Name="PART_MetroActiveDialogContainer" />
                </Grid>
            </AdornerDecorator>
            <Border x:Name="PART_Border"
                    BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}"
                    UseLayoutRounding="True"
                    HorizontalAlignment="Stretch"
                    VerticalAlignment="Stretch" />
            <ResizeGrip x:Name="WindowResizeGrip"
                        HorizontalAlignment="Right"
                        IsTabStop="false"
                        UseLayoutRounding="True"
                        Visibility="Collapsed"
                        VerticalAlignment="Bottom" />
        </Grid>

        <ControlTemplate.Resources>
            <Storyboard x:Key="OverlayFastSemiFadeIn"
                        BeginTime="0:0:0"
                        AccelerationRatio=".97"
                        Storyboard.TargetProperty="Opacity"
                        SpeedRatio="2.7">
                <DoubleAnimation To=".7" />
            </Storyboard>
            <Storyboard x:Key="OverlayFastSemiFadeOut"
                        BeginTime="0:0:0"
                        AccelerationRatio=".97"
                        Storyboard.TargetProperty="Opacity"
                        SpeedRatio="2.7">
                <DoubleAnimation To="0." />
            </Storyboard>
        </ControlTemplate.Resources>
        <ControlTemplate.Triggers>
            <!-- handle active/inactive state -->
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsActive"
                               Value="False" />
                    <Condition Property="GlowBrush"
                               Value="{x:Null}" />
                </MultiTrigger.Conditions>
                <Setter TargetName="PART_Border"
                        Property="BorderBrush"
                        Value="{Binding Path=NonActiveBorderBrush, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Controls:MetroWindow}}}" />
            </MultiTrigger>
            <Trigger Property="BorderBrush"
                     Value="{x:Null}">
                <Setter TargetName="PART_Border"
                        Property="Visibility"
                        Value="Collapsed" />
            </Trigger>
            <!-- no icon and no icon content template -> collapse the icon content control -->
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="Icon"
                               Value="{x:Null}" />
                    <Condition Property="IconTemplate"
                               Value="{x:Null}" />
                </MultiTrigger.Conditions>
                <Setter TargetName="PART_Icon"
                        Property="Visibility"
                        Value="Collapsed" />
                <Setter TargetName="PART_Icon"
                        Property="MinWidth"
                        Value="0" />
            </MultiTrigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="ResizeMode"
                               Value="CanResizeWithGrip" />
                    <Condition Property="WindowState"
                               Value="Normal" />
                </MultiTrigger.Conditions>
                <Setter Property="Visibility"
                        TargetName="WindowResizeGrip"
                        Value="Visible" />
            </MultiTrigger>
            <Trigger Property="TitleCaps"
                     Value="True">
                <Setter TargetName="TitleControl"
                        Property="Content"
                        Value="{Binding Path=Title, Converter={StaticResource ToUpperConverter}, RelativeSource={RelativeSource TemplatedParent}}" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <Style TargetType="{x:Type Controls:MetroWindow}"
           BasedOn="{StaticResource {x:Type Controls:MetroWindow}}"
           x:Key="CleanWindowStyleKey">

        <Setter Property="ShowTitleBar"
                Value="True" />
        <Setter Property="MinWidth"
                Value="400" />
        <Setter Property="Template"
                Value="{StaticResource CleanWindowTemplate}" />
        <Setter Property="TitleForeground"
                Value="{DynamicResource BlackBrush}" />
        <Setter Property="OverrideDefaultWindowCommandsBrush"
                Value="{DynamicResource BlackBrush}" />
        <Setter Property="WindowMinButtonStyle"
                Value="{DynamicResource CleanWindowButtonStyle}" />
        <Setter Property="WindowMaxButtonStyle"
                Value="{DynamicResource CleanWindowButtonStyle}" />
        <Setter Property="WindowCloseButtonStyle"
                Value="{DynamicResource CleanCloseWindowButtonStyle}" />

    </Style>

    <Style x:Key="CleanWindowButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource MetroWindowButtonStyle}">

        <Style.Triggers>

            <Trigger Property="IsPressed" Value="True">
                <Setter Property="Background" Value="{DynamicResource AccentColorBrush}" />
                <Setter Property="Foreground" Value="White" />
            </Trigger>
            <Trigger Property="IsEnabled"
                     Value="false">
                <Setter Property="Foreground"
                        Value="{DynamicResource IdealForegroundDisabledBrush}" />
            </Trigger>

        </Style.Triggers>
    </Style>

    <Style x:Key="CleanCloseWindowButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource CleanWindowButtonStyle}">
        <Style.Triggers>

            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Background" Value="#EB2F2F" />
                <Setter Property="Foreground" Value="{DynamicResource WhiteBrush}" />
            </Trigger>
            <Trigger Property="IsPressed" Value="True">
                <Setter Property="Background" Value="#7C0000" />
            </Trigger>

        </Style.Triggers>
    </Style>

</ResourceDictionary>